#!/usr/bin/env python

""" A Redis appendonly file parser
"""

import logging
import hiredis
import sys

if len(sys.argv) != 2:
   print(sys.argv[0], 'AOF_file')
   sys.exit()
file = open(sys.argv[1], mode='rb')
line = file.readline()
cur_request = line
while line:
    req_reader = hiredis.Reader()
    req_reader.setmaxbuf(0)
    req_reader.feed(cur_request)
    command = req_reader.gets()
    try:
        if command is not False:
            print (command)
            cur_request = b''
    except hiredis.ProtocolError:
        print ('protocol error')
    line = file.readline()
    cur_request += line
file.close
